
// 获取设备的DPI
function getDeviceDPI() {
  const devicePixelRatio = window.devicePixelRatio || 1;
  const backingStoreRatio =
    window.screen.deviceXDPI / window.screen.logicalXDPI || 1;
  return devicePixelRatio || backingStoreRatio;
}


// 转换cm为像素
function cmToPx(cm: number) {
  const dpi = getDeviceDPI();
  const inchPerCm = 0.3937007874015748;
  return cm * inchPerCm * dpi;
}


/**
 * 像素点转rem
 */
function pxToRem(px: number) {
  const rootFontSize = 16;
  const rem = px / rootFontSize;
  return rem;
}


/**
 * Point转px
 */
function pointsToPixels(points: number) {
  return points * 96 / 72;
}

/**
 * 像素转Point
 */
function pixelsToPoints(pixels: number) {
  return pixels * 72 / 96;
}


export {
  getDeviceDPI,
  cmToPx,
  pxToRem,
  pointsToPixels,
  pixelsToPoints
}